import Vue from 'vue'
import api from '../../apis'
import * as types from '../types'

export default {
	state: {
		company: null
	},
	mutations: {
		SET_COMPANY: (state, data) => {
			Vue.set(state, 'company', data);
		}
	},
	actions: {
		/**
		 * 获取企业信息
		 * @param commit
		 */
		fetchCompany ({ commit }) {
			api.company.fetch().then(response => {
				commit(types.SET_COMPANY, response.data);
			})
		},
		/**
		 * 创建企业信息
		 * @param commit
		 * @param params
		 */
		store ({ commit }, params) {
			api.company.store(params).then(response => {
				commit(types.SET_COMPANY, response.data);
			})
		},
		/**
		 * 更新企业信息
		 * @param commit
		 * @param options
		 */
		update ({ commit }, options) {
			api.company.update(options.id, options.params).then(response => {
				commit(types.SET_COMPANY, response.data);
			})
		}
	},
}
